from django.db import models
from barrelhouse.core.vendors.models import vendor_account, contact

class site(models.Model):
    '''defines a location that can house one or more datacenters'''

    name = models.CharField(max_length=50, help_text="Name for Location")
    abbreviation = models.CharField(max_length=3, help_text="3 character abbreviation for site")
    address1 = models.CharField(max_length=50, help_text="address line 1")
    address2 = models.CharField(max_length=50, blank=True, null=True, help_text="address line 2")
    city = models.CharField(max_length=50, help_text="city")
    state = models.CharField(max_length=2, help_text="state")
    zip = models.CharField(max_length=10, help_text="zip code")
    site_contact_phone = models.CharField(max_length=12, blank=True, null=True, help_text="phone number for site contact")
    notes = models.TextField(help_text="notes about this site (optional)", null=True, blank=True)

    def get_absolute_url(self):
        return "sites/%i/" % self.abbreviation

    def full_address(self):
        addy = self.name + "<br/>" + self.address1 + "<br/>" + self.address2 + "<br/>" + self.city + ", " + self.state + " " + self.zip

        return addy

    full_address.allow_tags = True

    def __unicode__(self):
        return self.name

class datacenter(models.Model):
    '''defines datacenters within a site'''

    name = models.CharField(max_length=50, help_text="a specific colocation within a site")
    site = models.ForeignKey(site, help_text="site housing this datacenter")
    vendor = models.ForeignKey(contact, verbose_name="Primary Contact", help_text="Associated Account for this datacenter")
    power = models.IntegerField(max_length=4, help_text="power, in kVA, for this datacenter")
    form_factor = models.DecimalField(max_length=4, decimal_places=1, max_digits=4, help_text="space, in U, for this datacenter")
    notes = models.TextField(verbose_name="Note", help_text="notes about this datacenter")

    def get_absolute_url(self):
        return "datacenters/%i/" % self.name

    def __unicode__(self):
        return self.name

